import SwiftUI

struct KeyboardButton: View {
    let key: String
    let shiftEnabled: Bool
    let action: () -> Void
    
    var body: some View {
        Button(action: action) {
            Group {
                if key == "delete" {
                    Image(systemName: "delete.left")
                        .font(.system(size: 15))
                } else if key == "shift" {
                    Image(systemName: shiftEnabled ? "shift.fill" : "shift")
                        .font(.system(size: 15))
                } else {
                    Text(shiftEnabled ? key.uppercased() : key)
                        .font(.system(size: 18))
                }
            }
            .frame(minWidth: getKeyWidth(), minHeight: 40)
            .foregroundColor(.black) // 明确设置前景色为黑色
            .background(getKeyColor())
            .cornerRadius(5)
        }
        .buttonStyle(PlainButtonStyle()) // 使用PlainButtonStyle避免iOS默认按钮样式干扰
    }
    
    // 获取按键宽度
    private func getKeyWidth() -> CGFloat {
        switch key {
        case "delete", "shift":
            return 45
        case "#+=":
            return 45
        default:
            return 32
        }
    }
    
    // 获取按键颜色
    private func getKeyColor() -> Color {
        switch key {
        case "delete", "shift", "#+=":
            return Color(.systemGray3)
        default:
            return Color(.systemGray5)
        }
    }
}